﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileSelector.aspx.cs" Inherits="SiteWorx_FileSelector" Theme="Admin" StylesheetTheme="Admin"%>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>File Selector</title>

    <script type="text/javascript">
        //A function that will return a reference to the parent radWindow in case the page is loaded in a RadWindow object
        function getRadWindow() {
            var oWindow = null;
            if (window.radWindow) oWindow = window.radWindow;
            else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
            return oWindow;
        }
        function OnClientGridDblClick(sender, args) {
            var item = args.get_item();

            //If file (and not a folder) is selected - call the OnFileSelected method on the parent page
            if (item.get_type() == Telerik.Web.UI.FileExplorerItemType.File) {
                args.set_cancel(true);
                //Get a reference to the opener parent page using rad window
                var wnd = getRadWindow();
                var openerPage = wnd.BrowserWindow;
                var path = item.get_path();
                path = path.substring(path.indexOf("/Files"), path.length);
                
                //if you need the URL for the item, use get_url() instead of get_path()
                openerPage.OnFileSelected(wnd, path);
                //Close window
                wnd.close();
            }
        }
    </script>

</head>
<body>
    <form id="frmFileSelector" runat="server">
        <telerik:radstylesheetmanager id="rssFileManager" runat="server"/>
        <telerik:radscriptmanager id="smFileManager" runat="server" enabletheming="True"/>
        <telerik:radformdecorator id="rfdFileManager" runat="server" skin="Telerik" DecoratedControls="CheckBoxes, RadioButtons" />
        <telerik:RadFileExplorer runat="server" ID="fexpFileExplorer" Width="685" Height="300" OnClientFileOpen="OnClientGridDblClick">
            <Configuration ViewPaths="~/Files" DeletePaths="~/Files" UploadPaths="~/Files" />
        </telerik:RadFileExplorer>
    </form>
</body>
</html>
